﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySoft.Data;

namespace Caifu.Datas
{
	/// <summary>
	/// 基金管理人
	/// </summary>
	public class InvestAdvisorData
	{
		/// <summary>
		/// 实例
		/// </summary>
		public static readonly InvestAdvisorData Instance = new InvestAdvisorData();

		private readonly DbSession dbSession = new DbSession("Caifu");

		/// <summary>
		/// 新增基金管理人
		/// </summary>
		/// <param name="investAdvisor"></param>
		public void AddInvestAdvisor(InvestAdvisor investAdvisor)
		{
			investAdvisor.Detach();
			if (investAdvisor.Id == Guid.Empty) investAdvisor.Id = Itfort.Comb.NewComb();
			if (investAdvisor.AddTime == DateTime.MinValue) investAdvisor.AddTime = DateTime.Now;
			if (investAdvisor.UpdateTime == DateTime.MinValue) investAdvisor.UpdateTime = DateTime.Now;
			dbSession.Save<InvestAdvisor>(investAdvisor);
		}

		/// <summary>
		/// 修改基金管理人
		/// </summary>
		/// <param name="investAdvisor"></param>
		public void UpdateInvestAdvisor(InvestAdvisor investAdvisor)
		{
			investAdvisor.Attach();
			investAdvisor.UpdateTime = DateTime.Now;
			dbSession.Save<InvestAdvisor>(investAdvisor);
		}

		/// <summary>
		/// 删除基金管理人
		/// </summary>
		/// <param name="id"></param>
		public void DeleteInvestAdvisor(Guid id)
		{
			dbSession.Delete<InvestAdvisor>(id);
		}

		/// <summary>
		/// 获取基金管理人
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public InvestAdvisor GetInvestAdvisor(Guid id)
		{
			return dbSession.Single<InvestAdvisor>(id);
		}

		/// <summary>
		/// 获取基金管理人
		/// </summary>
		/// <param name="pageIndex"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		public IList<InvestAdvisor> GetInvestAdvisors(Int32 pageIndex, Int32 pageSize)
		{
			return dbSession.From<InvestAdvisor>()
				.GetPage(pageSize).ToList(pageIndex);
		}
	}
}

